package com.sino.operation.service.business;

import com.alibaba.fastjson.JSON;
import com.sino.operation.commons.ConstantValue;
import com.sino.operation.entity.BizOperateLog;
import com.sino.operation.entity.BizTranslist;
import com.sino.operation.mapper.BizTranslistMapper;
import com.sino.operation.param.out.ComplateParam;
import com.sino.operation.param.out.EscBodyByCounterInquire;
import com.sino.operation.param.out.InquirePublicParam;
import com.sino.operation.param.out.TerminalParam;
import com.sino.operation.util.StringUtil;
import com.sino.operation.util.TimeUtil;
import com.sino.operation.vo.CompleteFlowParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.HashMap;
import java.util.Map;

@Service
public class ComplateTaskService {
   @Autowired
   private BizTranslistMapper bizTranslistMapper;

    public boolean  taskHandle(EscBodyByCounterInquire counterInquire){
        BizOperateLog bizOperateLog = new BizOperateLog();
        HashMap<String, Object> stopFlowParam = new HashMap<>(16);
        HashMap<String, Object> varMap = new HashMap<>();
        InquirePublicParam inquirePublicParam = counterInquire.getInquirePublicParam();
        ComplateParam complateParam= (ComplateParam) counterInquire.getObject();
        String orgCode = inquirePublicParam.getOrgCode();
        String taskId = complateParam.getTaskId();
        String journalNo = complateParam.getJournalNo();//流水号
        String tellerCode = complateParam.getTellerCode();//柜员号
        String tellerPost = complateParam.getTellerPost();//柜员岗位


        bizOperateLog.setId(StringUtil.getId());
        bizOperateLog.setJournalNo(journalNo);
        bizOperateLog.setTellerNo(tellerCode);
        bizOperateLog.setTellerPost(tellerPost);
        bizOperateLog.setOrganId(orgCode);
        bizOperateLog.setOperateType(ConstantValue.OPER_REPEATCHECK_COMPLETE);
        bizOperateLog.setOperDate(TimeUtil.getStandardTime());
        CompleteFlowParam completeFlowParam = new CompleteFlowParam();
        completeFlowParam.setTaskId(taskId);
        completeFlowParam.setMaps(varMap);
        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.postForObject(ConstantValue.FLOWMANAGER + ConstantValue.STOP_TASK, stopFlowParam, String.class);
        Map map = JSON.parseObject(result, Map.class);
        String code = map.get("code").toString();
        if (!"200".equals(code)){
            return false;
        }
        return true;
    }
}
